*************** Preamble
***************
***************

***Set Stata Options
clear 
cap clear matrix
cap clear mata
set more off
cap set mat 800
cap set mem 500m

***Set Directories
global maindirectory C:\Users\Economics\Dropbox\Research\Working Papers\War in History\EHDR revision materials\ /*Update path to relevant working directory*/
global rawdata $maindirectory\Raw Data\
global cleandata $maindirectory\Clean Data\
global maps $maindirectory\Maps\
global lights $maindirectory\Maps\Lights\
global dodir $maindirectory\Do Files\DFOReplication\
global output $maindirectory\Output\

***Output Options
global outopts st(coef se pval) paren(se) br(pval) bdec(3) nocon excel

***Set Globals
global mainrhs conflict_brecke conflict_breckeXwb_ssa
global contdummies asia oceania northafrica wb_ssa
global maincont ln_pd1500 ln_yst ln_suitavg ln_abslat area2
global baselinecont $maincont $contdummies

*************** Table 1: Conflicts by Century and Continent, 1400-1799
***************
***************

*** Conflict starts by century and continent
cd "$cleandata\"
use "dfo_panel_ehdr", clear	
cd "$output\"

*Collapse as conflict starts	
keep year europe asia oceania americas wb_ssa northafrica conflictstart_brecke
gen continent=""
	replace continent="Europe" if europe==1
	replace continent="Asia" if asia==1
	replace continent="Oceania" if oceania==1
	replace continent="Americas" if americas==1
	replace continent="Sub-Saharan Africa" if wb_ssa==1
	replace continent="North Africa" if northafrica==1
gen century=100*floor(year/100)	
collapse (sum) conflictstart_brecke, by(continent century)
rename conflictstart_brecke conflictstarts_brecke
	label var conflictstarts_brecke "Conflicts starting in century"
	label var continent "Continent"
	label var century "Century"

*Add averages and totals
bysort continent : egen total=total(conflictstarts_brecke)
bysort continent : egen mean=mean(conflictstarts_brecke)
	
*Save counts
outsheet using table1.csv, comma replace 

*************** Table 2: Historical Conflict and State Capacity: Main Results
***************
***************
*Load Data
cd "$cleandata"
use "dfo_cross_section_ehdr", clear
cd "$output"

*Restrict sample
keep if americas==0
keep if oceania==0

***Main results: capacity
	*Column 1: Baseline (Direct tax share)
	*Column 2: Income tax share 1999
	*Column 3: Income tax bias 1999
	*Column 4: Tax to GDP ratio 1999	
cap erase table2.txt
cap erase table2.xml
foreach X in inctaximf9014 dirtaximf9014 incgdpimf9014ratio taxgdpimf9014 {
		reg `X' $mainrhs $baselinecont, r
		su `X' if e(sample)
			local lhssd=r(sd)
		su conflict_brecke if e(sample)
			local rhssd=r(sd)
		local stdB=_b[conflict_brecke]*`rhssd'/`lhssd'
		local stdBssa=(_b[conflict_brecke]+_b[conflict_breckeXwb_ssa])*`rhssd'/`lhssd'
		test conflict_brecke+conflict_breckeXwb_ssa=0
		local Fstat=r(F)
		local Pval=r(p)
		outreg2 using table2, keep($mainrhs) $outopts ///
		addstat(F,`Fstat',p,`Pval',Standardized B,`stdB',Standardized B for SSA,`stdBssa') addtext(Continent FE, Yes, Controls, Yes) append
}
 
	*Column 5: Number of conflicts
	*Column 6: Conflict starts
foreach X in cstart_brecke {
		reg inctaximf9014 `X' `X'Xwb_ssa $baselinecont, r
		test `X'+`X'Xwb_ssa=0
		local Fstat=r(F)
		local Pval=r(p)
		outreg2 using table2, keep(`X' `X'Xwb_ssa) $outopts ///
		addstat(F,`Fstat',p,`Pval') addtext(Continent FE, Yes, Controls, Yes) append
}
cap erase table2.txt

*************** Table 3: Persistence of Conflict: Main Results
***************
***************
*Load Data
cd "$cleandata"
use "dfo_cross_section_ehdr", clear
cd "$output"

*Restrict sample
keep if americas==0
keep if oceania==0

***Main results: conflict
	*Column 1: Baseline (Civil war share)
	*Column 2: Ordered violence measure
	*Column 3: Dummy violence measure
cap erase table3.txt
cap erase table3.xml
foreach X in avg_civilwar00 repdum_purPRIO violence {
		reg `X' $mainrhs $baselinecont, r
		su `X' if e(sample)
			local lhssd=r(sd)
		su conflict_brecke if e(sample)
			local rhssd=r(sd)
		local stdB=_b[conflict_brecke]*`rhssd'/`lhssd'
		local stdBssa=(_b[conflict_brecke]+_b[conflict_breckeXwb_ssa])*`rhssd'/`lhssd'
		test conflict_brecke+conflict_breckeXwb_ssa=0
		local Fstat=r(F)
		local Pval=r(p)
		outreg2 using table3, keep($mainrhs) $outopts ///
		addstat(F,`Fstat',p,`Pval',Standardized B,`stdB',Standardized B for SSA,`stdBssa') addtext(Continent FE, Yes, Controls, Yes) append
}

	*Column 4: Number of conflicts
	*Column 5: Conflict Starts
foreach X in cstart_brecke {
		reg avg_civilwar00 `X' `X'Xwb_ssa $baselinecont, r
		test `X'+`X'Xwb_ssa=0
		local Fstat=r(F)
		local Pval=r(p)
		outreg2 using table3, keep(`X' `X'Xwb_ssa) $outopts ///
		addstat(F,`Fstat',p,`Pval') addtext(Continent FE, Yes, Controls, Yes) append
}

cap erase table3.txt

*************** Table 4: Historical Conflict and State Capacity: Robustness
***************
***************
*Load Data
cd "$cleandata"
use "dfo_cross_section_ehdr", clear
cd "$output"

*Restrict sample
keep if americas==0
keep if oceania==0

***Robustness: omitted vars, capacity
cap erase table4.txt
cap erase table4.xml

	*Column : Add colonial origins
reg inctaximf9014 $mainrhs $baselinecont ///
		colony_esp colony_gbr colony_fra colony_prt colony_oeu, r
		test conflict_brecke+conflict_breckeXwb_ssa=0
		local Fstat=r(F)
		local Pval=r(p)
		outreg2 using table4, keep($mainrhs) $outopts ///
		addstat(F,`Fstat',p,`Pval') addtext(Continent FE, Yes, Controls, colony_esp colony_gbr colony_fra colony_prt colony_oeu) append
	*Column : Add artificial borders
reg inctaximf9014 $mainrhs $baselinecont ///
		fractal, r
		test conflict_brecke+conflict_breckeXwb_ssa=0
		local Fstat=r(F)
		local Pval=r(p)
		outreg2 using table4, keep($mainrhs) $outopts ///
		addstat(F,`Fstat',p,`Pval') addtext(Continent FE, Yes, Controls, fractal) append
	*Column : Add legal origins
reg inctaximf9014 $mainrhs $baselinecont ///
		legor_uk legor_fr, r
		test conflict_brecke+conflict_breckeXwb_ssa=0
		local Fstat=r(F)
		local Pval=r(p)
		outreg2 using table4, keep($mainrhs) $outopts ///
		addstat(F,`Fstat',p,`Pval') addtext(Continent FE, Yes, Controls, legor_uk legor_fr) append
	*Column : Add other initial conditions
reg inctaximf9014 $mainrhs $baselinecont ///
		tech1500AD stateantiquity, r
		test conflict_brecke+conflict_breckeXwb_ssa=0
		local Fstat=r(F)
		local Pval=r(p)
		outreg2 using table4, keep($mainrhs) $outopts ///
		addstat(F,`Fstat',p,`Pval') addtext(Continent FE, Yes, Controls, tech1500AD stateantiquity) append
	*Column : Other geography
reg inctaximf9014 $mainrhs $baselinecont ///
		malfal kgatr distcr dist_coast rugged desert2 gemstones2, r
		test conflict_brecke+conflict_breckeXwb_ssa=0
		local Fstat=r(F)
		local Pval=r(p)
		outreg2 using table4, keep($mainrhs) $outopts ///
		addstat(F,`Fstat',p,`Pval') addtext(Continent FE, Yes, Controls, malfal kgatr distcr dist_coast rugged desert2 gemstones2) append
	*Column : Legal origins and other geography
reg inctaximf9014 $mainrhs $baselinecont ///
		colony_esp colony_gbr colony_fra colony_prt colony_oeu ///
		fractal ///
		legor_uk legor_fr ///
		malfal kgatr distcr dist_coast rugged desert2 gemstones2, r
		test conflict_brecke+conflict_breckeXwb_ssa=0
		local Fstat=r(F)
		local Pval=r(p)
		outreg2 using table4, keep($mainrhs) $outopts ///
		addstat(F,`Fstat',p,`Pval') addtext(Continent FE, Yes, Controls, all but init cond) append
cap erase table4.txt

*************** Table 5: Persistence of Conflict: Robustness
***************
***************
*Load Data
cd "$cleandata"
use "dfo_cross_section_ehdr", clear
cd "$output"

*Restrict sample
keep if americas==0
keep if oceania==0

***Robustness: omitted vars, conflict
cap erase table5.txt
cap erase table5.xml
	*Column : Add colonial origins
reg avg_civilwar00 $mainrhs $baselinecont ///
		colony_esp colony_gbr colony_fra colony_prt colony_oeu, r
		test conflict_brecke+conflict_breckeXwb_ssa=0
		local Fstat=r(F)
		local Pval=r(p)
		outreg2 using table5, keep($mainrhs) $outopts ///
		addstat(F,`Fstat',p,`Pval') addtext(Continent FE, Yes, Controls, colony_esp colony_gbr colony_fra colony_prt colony_oeu) append	
	*Column : Add artificial borders
reg avg_civilwar00 $mainrhs $baselinecont ///
		fractal, r
		test conflict_brecke+conflict_breckeXwb_ssa=0
		local Fstat=r(F)
		local Pval=r(p)
		outreg2 using table5, keep($mainrhs) $outopts ///
		addstat(F,`Fstat',p,`Pval') addtext(Continent FE, Yes, Controls, fractal) append
	*Column : Add legal origins
reg avg_civilwar00 $mainrhs $baselinecont ///
		legor_uk legor_fr, r
		test conflict_brecke+conflict_breckeXwb_ssa=0
		local Fstat=r(F)
		local Pval=r(p)
		outreg2 using table5, keep($mainrhs) $outopts ///
		addstat(F,`Fstat',p,`Pval') addtext(Continent FE, Yes, Controls, legor_uk legor_fr) append
	*Column : Add other initial conditions		
reg avg_civilwar00 $mainrhs $baselinecont ///
		tech1500AD stateantiquity, r
		test conflict_brecke+conflict_breckeXwb_ssa=0
		local Fstat=r(F)
		local Pval=r(p)
		outreg2 using table5, keep($mainrhs) $outopts ///
		addstat(F,`Fstat',p,`Pval') addtext(Continent FE, Yes, Controls, tech1500AD stateantiquity) append
	*Column : Other geography		
reg avg_civilwar00 $mainrhs $baselinecont ///
		malfal kgatr distcr dist_coast rugged desert2 gemstones2, r
		test conflict_brecke+conflict_breckeXwb_ssa=0
		local Fstat=r(F)
		local Pval=r(p)
		outreg2 using table5, keep($mainrhs) $outopts ///
		addstat(F,`Fstat',p,`Pval') addtext(Continent FE, Yes, Controls, malfal kgatr distcr dist_coast rugged desert2 gemstones2) append
	*Column : Legal origins and other geography	
reg avg_civilwar00 $mainrhs $baselinecont ///
		colony_esp colony_gbr colony_fra colony_prt colony_oeu ///
		fractal ///
		legor_uk legor_fr ///
		malfal kgatr distcr dist_coast rugged desert2 gemstones2, r
		test conflict_brecke+conflict_breckeXwb_ssa=0
		local Fstat=r(F)
		local Pval=r(p)
		outreg2 using table5, keep($mainrhs) $outopts ///
		addstat(F,`Fstat',p,`Pval') addtext(Continent FE, Yes, Controls, all but init cond openness) append
cap erase table5.txt

*************** Table 6: Potential Bias from Unobservables
***************
***************
*Load Data
cd "$cleandata"
use "dfo_cross_section_ehdr", clear
cd "$output"

*Restrict sample
keep if americas==0
keep if oceania==0

***Potential bias tests 
***Compute AET Statistics for conflict_brecke
preserve
	*Define sets of controls
	global alwayscontrols $mainrhs $contdummies
	global baselinecontrols ln_pd1500 ln_yst ln_suitavg ln_abslat area
	global colonizerfe colony_esp colony_gbr colony_fra colony_prt colony_oeu
	global legorfe legor_uk legor_fr
	global techstate tech1500AD stateantiquity
	global othergeog malfal kgatr distcr dist_coast rugged desert gemstones

	*Define variables for storing outcomes
	set obs 1000
	gen rowno=_n
	gen outcome=""
	gen restrictedcontrols=""
	gen fullcontrols=""
	gen restrictedcoef=.
	gen fullcoef=.
	gen aetstat=.

	local i=0
	*Baseline: Conflict, Continents, Interaction
	foreach depvar of varlist inctaximf9014 avg_civilwar00 {
	foreach controlset in baselinecontrols colonizerfe legorfe techstate othergeog ///
		{
		local i=`i'+1
		qui reg `depvar' $alwayscontrols ${`controlset'} , r
		gen sample=e(sample)==1
		replace outcome="`depvar'" if rowno==`i' 
		replace fullcontrols="${`controlset'}" if rowno==`i' 
		replace fullcoef=_b[conflict_brecke] if rowno==`i' 
		qui reg `depvar' $alwayscontrols if sample==1, r
		replace outcome="`depvar'" if rowno==`i' 
		replace restrictedcontrols="$alwayscontrols" if rowno==`i' 
		replace restrictedcoef=_b[conflict_brecke] if rowno==`i' 
		replace aetstat=fullcoef/(restrictedcoef-fullcoef) if rowno==`i' 
		drop sample
	}
	}

	*Baseline: Conflict, Continents, Interaction, Main control set
	foreach depvar of varlist inctaximf9014 avg_civilwar00 {
	foreach controlset in colonizerfe legorfe techstate othergeog ///
		{
		local i=`i'+1
		qui reg `depvar' $alwayscontrols $baselinecontrols ${`controlset'}, r
		gen sample=e(sample)==1
		replace outcome="`depvar'" if rowno==`i' 
		replace fullcontrols="${`controlset'}" if rowno==`i' 
		replace fullcoef=_b[conflict_brecke] if rowno==`i' 
		qui reg `depvar' $alwayscontrols $baselinecontrols if sample==1, r
		replace outcome="`depvar'" if rowno==`i' 
		replace restrictedcontrols="$alwayscontrols $baselinecontrols" if rowno==`i' 
		replace restrictedcoef=_b[conflict_brecke] if rowno==`i' 
		replace aetstat=fullcoef/(restrictedcoef-fullcoef) if rowno==`i' 
		drop sample
	}
	}

	keep rowno outcome restrictedcontrols fullcontrols restrictedcoef fullcoef aetstat
	order rowno outcome restrictedcontrols fullcontrols restrictedcoef fullcoef aetstat
	drop if aetstat==.
	outsheet using table6A.csv, comma replace
restore

***Compute AET Statistics for conflict_breckeXwb_ssa
preserve
	*Define sets of controls
	global alwayscontrols $mainrhs $contdummies
	global baselinecontrols ln_pd1500 ln_yst ln_suitavg ln_abslat area
	global colonizerfe colony_esp colony_gbr colony_fra colony_prt colony_oeu
	global legorfe legor_uk legor_fr
	global techstate tech1500AD stateantiquity
	global othergeog malfal kgatr distcr dist_coast rugged desert gemstones

	*Define variables for storing outcomes
	set obs 1000
	gen rowno=_n
	gen outcome=""
	gen restrictedcontrols=""
	gen fullcontrols=""
	gen restrictedcoef=.
	gen fullcoef=.
	gen aetstat=.

	local i=0
	*Baseline: Conflict, Continents, Interaction
	foreach depvar of varlist inctaximf9014 avg_civilwar00 {
	foreach controlset in baselinecontrols colonizerfe legorfe techstate othergeog ///
		{
		local i=`i'+1
		qui reg `depvar' $alwayscontrols ${`controlset'} , r
		gen sample=e(sample)==1
		replace outcome="`depvar'" if rowno==`i' 
		replace fullcontrols="${`controlset'}" if rowno==`i' 
		replace fullcoef=_b[conflict_breckeXwb_ssa] if rowno==`i' 
		qui reg `depvar' $alwayscontrols if sample==1, r
		replace outcome="`depvar'" if rowno==`i' 
		replace restrictedcontrols="$alwayscontrols" if rowno==`i' 
		replace restrictedcoef=_b[conflict_breckeXwb_ssa] if rowno==`i' 
		replace aetstat=fullcoef/(restrictedcoef-fullcoef) if rowno==`i' 
		drop sample
	}
	}

	*Baseline: Conflict, Continents, Interaction, Main control set
	foreach depvar of varlist inctaximf9014 avg_civilwar00 {
	foreach controlset in colonizerfe legorfe techstate othergeog ///
		{
		local i=`i'+1
		qui reg `depvar' $alwayscontrols $baselinecontrols ${`controlset'}, r
		gen sample=e(sample)==1
		replace outcome="`depvar'" if rowno==`i' 
		replace fullcontrols="${`controlset'}" if rowno==`i' 
		replace fullcoef=_b[conflict_breckeXwb_ssa] if rowno==`i' 
		qui reg `depvar' $alwayscontrols $baselinecontrols if sample==1, r
		replace outcome="`depvar'" if rowno==`i' 
		replace restrictedcontrols="$alwayscontrols $baselinecontrols" if rowno==`i' 
		replace restrictedcoef=_b[conflict_breckeXwb_ssa] if rowno==`i' 
		replace aetstat=fullcoef/(restrictedcoef-fullcoef) if rowno==`i' 
		drop sample
	}
	}

	keep rowno outcome restrictedcontrols fullcontrols restrictedcoef fullcoef aetstat
	order rowno outcome restrictedcontrols fullcontrols restrictedcoef fullcoef aetstat
	drop if aetstat==.
	outsheet using table6B.csv, comma replace
restore

*************** Table 7: Alternative Samples
***************
***************

***Robustness: different samples 
cap erase table7.txt
cap erase table7.xml

*1400-1700
cd "$cleandata"
use "dfo_cross_section_ehdr", clear
cd "$output"
keep if americas==0
keep if oceania==0

foreach X in inctaximf9014 avg_civilwar00 {
		reg `X' conflict_brecke_1400_1700 conflict_1400_1700_breckeXwb_ssa $baselinecont, r
		test conflict_brecke_1400_1700+conflict_1400_1700_breckeXwb_ssa=0
		local Fstat=r(F)
		local Pval=r(p)
		outreg2 using table7, keep(conflict_brecke_1400_1700 conflict_1400_1700_breckeXwb_ssa) $outopts ///
		addstat(F,`Fstat',p,`Pval') addtext(Continent FE, Yes, Controls, 1400-1700) append
}

*No ZAF
cd "$cleandata"
use "dfo_cross_section_ehdr", clear
cd "$output"
drop if country_ag=="South Africa"
keep if americas==0
keep if oceania==0

foreach X in inctaximf9014 avg_civilwar00 {
		reg `X' $mainrhs $baselinecont, r
		test conflict_brecke+conflict_breckeXwb_ssa=0
		local Fstat=r(F)
		local Pval=r(p)
		outreg2 using table7, keep($mainrhs) $outopts ///
		addstat(F,`Fstat',p,`Pval') addtext(Continent FE, Yes, Controls, No ZAF) append
}

*No CHN RUS
cd "$cleandata"
use "dfo_cross_section_ehdr", clear
cd "$output"
keep if americas==0
keep if oceania==0
drop if country_ag=="China"
drop if country_ag=="Russian Federation"

foreach X in inctaximf9014 avg_civilwar00 {
		reg `X' $mainrhs $baselinecont, r
		test conflict_brecke+conflict_breckeXwb_ssa=0
		local Fstat=r(F)
		local Pval=r(p)
		outreg2 using table7, keep($mainrhs) $outopts ///
		addstat(F,`Fstat',p,`Pval') addtext(Continent FE, Yes, Controls, No CHN RUS) append
}

*Keep Americas
cd "$cleandata"
use "dfo_cross_section_ehdr", clear
cd "$output"
keep if oceania==0

foreach X in inctaximf9014 avg_civilwar00 {
		reg `X' $mainrhs $baselinecont americas, r
		test conflict_brecke+conflict_breckeXwb_ssa=0
		local Fstat=r(F)
		local Pval=r(p)
		outreg2 using table7, keep($mainrhs) $outopts ///
		addstat(F,`Fstat',p,`Pval') addtext(Continent FE, Yes, Controls, Keep Americas) append
}

cap erase table7.txt

*************** Table 8: Intermediate Outcomes
***************
***************
*Load Data
cd "$cleandata"
use "dfo_cross_section_ehdr", clear
cd "$output"

*Restrict sample
keep if americas==0
keep if oceania==0

cap erase table8.txt
cap erase table8.xml

	*Column 1: No colonizer dummies
foreach X in conflict_brecke {
		reg ln_rrkm1910 `X' `X'Xwb_ssa $baselinecont, r
		test `X'+`X'Xwb_ssa=0
		local Fstat=r(F)
		local Pval=r(p)
		outreg2 `X' `X'Xwb_ssa wb_ssa using table8, keep($mainrhs) $outopts ///
		addstat(F,`Fstat',p,`Pval') addtext(Continent FE, Yes, Controls, Yes) append
}
	*Column 2: Colonizer dummies
foreach X in conflict_brecke {
		reg ln_rrkm1910 `X' `X'Xwb_ssa $baselinecont ///
		colony_esp colony_gbr colony_fra colony_prt colony_oeu, r
		test `X'+`X'Xwb_ssa=0
		local Fstat=r(F)
		local Pval=r(p)
		outreg2 `X' `X'Xwb_ssa wb_ssa using table8, keep($mainrhs) $outopts ///
		addstat(F,`Fstat',p,`Pval') addtext(Continent FE, Yes, Controls, Colonial origins) append
}
	*Column 3: No colonizer dummies
foreach X in conflict_brecke {
		reg conflict_brecke_bothssa1850 `X' ln_pd1500 ln_yst ln_suitavg ln_abslat area2 if wb_ssa==1, r
		outreg2 `X' using table8, keep($mainrhs) $outopts ///
		addtext(Continent FE, Yes, Controls, Yes) append
}
	*Column 4: Colonizer dummies
foreach X in conflict_brecke {
		reg conflict_brecke_bothssa1850 `X' ln_pd1500 ln_yst ln_suitavg ln_abslat area2 ///
		colony_esp colony_gbr colony_fra colony_prt colony_oeu ///
		if wb_ssa==1, r
		outreg2 `X' using table8, keep($mainrhs) $outopts ///
		addtext(Continent FE, Yes, Controls, Colonial origins) append
}
cap erase table8.txt

*************** Figure 1: Historical Conflict across the Old World
***************
***************

*** Standard summary statistics
*Load Data
cd "$cleandata"
use "dfo_cross_section_ehdr", clear
cd "$output"

cd "$maps"
cap erase james1.dta				
cap erase jamesco1.dta
shp2dta using countryborders_oldworld_nooceania, data(james1) coord(jamesco1) genid(id)
use james1.dta, clear
cd "$cleandata"
replace ISO3=ISO3_1
sort ISO3 
save jamestemp, replace

cd "$cleandata"
use dfo_cross_section_ehdr, clear
rename id id_ag
gen ISO3=code
replace ISO3="AND" if country_ag=="Andorra"
replace ISO3="N/A" if country_ag=="Channel Islands"
replace ISO3="COD" if country_ag=="Congo, Dem. Rep."
replace ISO3="IMN" if country_ag=="Isle of Man"
replace ISO3="ROU" if country_ag=="Romania"
replace ISO3="SRB" if country_ag=="Serbia and Montenegro"
replace ISO3="TLS" if country_ag=="Timor-Leste"
replace ISO3="PSE" if country_ag=="West Bank and Gaza"
sort ISO3
merge ISO3 using jamestemp
drop if _merge==1 /*Channel Islands*/

***Define sample
keep if americas==0
keep if oceania==0

cd "$maps"
format conflict_brecke %5.3f
spmap conflict_brecke using "jamesco1.dta", title("`lvar'")  ///
	id(id) cln(10) fc(Blues2) legenda(on) legend(pos(5))
cd "$output"
graph export figure1.png, replace
window manage close graph

cd "$cleandata"
erase jamestemp.dta 

*************** Table A1: Descriptive Statistics
***************
***************

*** Standard summary statistics
*Load Data
cd "$cleandata"
use "dfo_cross_section_ehdr", clear
cd "$output"

*Restrict sample
keep if americas==0
keep if oceania==0

***Save summary statistics
preserve
	keep conflict_brecke nconflicts_brecke cstart_brecke ///
	inctaximf9014 inctaximf9014 biastaximf9014 taxgdpimf9014 formal ///
	avg_civilwar00 repdum_purPRIO violence ///
	europe $contdummies ///
	ln_pd1500 ln_yst ln_suitavg ln_abslat area2 ///
	colony_gbr colony_fra colony_prt colony_esp colony_oeu ///
	legor_uk legor_fr legor_so legor_ge legor_sc ///
	tech1500AD stateantiquity ///
	malfal kgatr distcr dist_coast rugged desert2 gemstones2 ///
	parl_dem ///
	pprotest pcatholic pmuslim pother ///
	efrac ///
	openness ///
	school trust ///
	ln_rrkm1910 ///
	ln_gdppc2000 ///
	biastaximf9014 taxgdpimf9014 dirtaximf9014 omtradetaximf9014 ///
	inctaximf9014  
	outreg2 using tableA1, replace sum(log) excel label 
restore

*Clean Up
erase tableA1.txt

*************** Other Appendix Tables
***************
***************

*** Table A2: Robustness: Non-Fiscal Outcomes
*government anti-diversion score
*state weakness score

*Load Data
cd "$cleandata"
use "dfo_cross_section_ehdr", clear
cd "$output"

*Restrict sample
keep if americas==0
keep if oceania==0

cap erase tableA2.txt
cap erase tableA2.xml
foreach X in mgadp97 state_weakness {
		reg `X' $mainrhs $baselinecont, r
		test conflict_brecke+conflict_breckeXwb_ssa=0
		local Fstat=r(F)
		local Pval=r(p)
		outreg2 using tableA2, keep($mainrhs) $outopts ///
		addstat(F,`Fstat',p,`Pval') addtext(Continent FE, Yes, Controls, Yes) append
}
cap erase tableA2.txt

*** Table A3: Robustness: Additional Interaction Terms
*Re-estimate spec 1 in Tables 2 and 3 after including interaction terms for Asia and North Africa
*Load Data
cd "$cleandata"
use "dfo_cross_section_ehdr", clear
cd "$output"

*Restrict sample
keep if americas==0
keep if oceania==0

foreach var in asia northafrica {
	gen conflict_breckeX`var'=conflict_brecke*`var'
}

cap erase tableA3.txt
cap erase tableA3.xml
foreach X in inctaximf9014 avg_civilwar00 {
		reg `X' $mainrhs $baselinecont ///
			conflict_breckeXasia conflict_breckeXnorthafrica, r
		test conflict_brecke+conflict_breckeXwb_ssa=0
		local Fstat=r(F)
		local Pval=r(p)
		outreg2 using tableA3, keep($mainrhs conflict_breckeX*) $outopts ///
		addstat(F,`Fstat',p,`Pval') addtext(Continent FE, Yes, Controls, Yes) append
}
cap erase tableA3.txt

*** Table A4: Robustness: Ethnicity Controls
cd "$output"
cap erase tableA4.txt
cap erase tableA4.xml

*Control for Ethnic Fractionalization from Alesina et al. (2002)
cd "$cleandata"
use "dfo_cross_section_ehdr", clear
cd "$output"
keep if americas==0
keep if oceania==0
foreach depvar in inctaximf9014 avg_civilwar00 {
	reg `depvar' $mainrhs $baselinecont ///
		efrac, r
		test conflict_brecke+conflict_breckeXwb_ssa=0
		local Fstat=r(F)
		local Pval=r(p)
	outreg2 using tableA4, keep($mainrhs) $outopts addstat(F,`Fstat',p,`Pval') ///
		addtext(Robustness, Control for Ethnic Fractionalization) append
}

*Control for ethnic dominance in terms of whether a single language is spoken by at least half of the country’s population based on data from the Joshua Project
foreach depvar in inctaximf9014 avg_civilwar00 {
	reg `depvar' $mainrhs $baselinecont ///
		dominant, r
		test conflict_brecke+conflict_breckeXwb_ssa=0
		local Fstat=r(F)
		local Pval=r(p)
	outreg2 using tableA4, keep($mainrhs) $outopts addstat(F,`Fstat',p,`Pval') ///
		addtext(Robustness, Control for Ethnic Dominance) append
}
cap erase tableA4.txt	

*** Table A5: Robustness: Post-Independence Controls
* Re-estimate spec 1 in Tables 2 and 3 after controlling for UN vote affinity
*Load Data
cd "$cleandata"
use "dfo_cross_section_ehdr", clear
cd "$output"

*Restrict sample
keep if americas==0
keep if oceania==0

cap erase tableA5.txt
cap erase tableA5.xml
foreach X in inctaximf9014 avg_civilwar00 {
		reg `X' $mainrhs $baselinecont ///
			s2un, r
		test conflict_brecke+conflict_breckeXwb_ssa=0
		local Fstat=r(F)
		local Pval=r(p)
		outreg2 using tableA5, keep($mainrhs) $outopts ///
		addstat(F,`Fstat',p,`Pval') addtext(Continent FE, Yes, Controls, Yes) append
}

* Re-estimate spec 1 in Tables 2 and 3 after controlling for educated leaders
foreach X in inctaximf9014 avg_civilwar00 {
		reg `X' $mainrhs $baselinecont ///
			meangraduate, r
		test conflict_brecke+conflict_breckeXwb_ssa=0
		local Fstat=r(F)
		local Pval=r(p)
		outreg2 using tableA5, keep($mainrhs) $outopts ///
		addstat(F,`Fstat',p,`Pval') addtext(Continent FE, Yes, Controls, Yes) append
}
cap erase tableA5.txt

*** Table A6: Robustness: Slavery Controls
*Re-estimate spec 1 in Tables 2 and 3 after controlling for indigenous slavery
*Load Data
cd "$cleandata"
use "dfo_cross_section_ehdr", clear
cd "$output"

*Restrict sample
keep if americas==0
keep if oceania==0

cap erase tableA6.txt
cap erase tableA6.xml
foreach X in inctaximf9014 avg_civilwar00 {
		reg `X' $mainrhs $baselinecont ///
			boltslavery boltslaverymissing, r
		test conflict_brecke+conflict_breckeXwb_ssa=0
		local Fstat=r(F)
		local Pval=r(p)
		outreg2 using tableA6, keep($mainrhs) $outopts ///
		addstat(F,`Fstat',p,`Pval') addtext(Continent FE, Yes, Controls, Yes) append
}

* Control for slave exports from Nunn
foreach depvar in inctaximf9014 avg_civilwar00 {
	reg `depvar' $mainrhs $baselinecont ///
		ln_export_area, r
		test conflict_brecke+conflict_breckeXwb_ssa=0
		local Fstat=r(F)
		local Pval=r(p)
	outreg2 using tableA6, keep($mainrhs) $outopts addstat(F,`Fstat',p,`Pval') ///
		addtext(Robustness, Control for Slave Exports) append
}
cap erase tableA6.txt

*** Table A7: Robustness: Additional Geographic Controls
*Re-estimate spec 6 in Tables 4 and 5 after controlling for ecological diversity
*Load Data
cd "$cleandata"
use "dfo_cross_section_ehdr", clear
cd "$output"

*Restrict sample
keep if americas==0
keep if oceania==0

cap erase tableA7.txt
cap erase tableA7.xml
foreach X in inctaximf9014 avg_civilwar00 {
		reg `X' $mainrhs $baselinecont ///
		malfal kgatr distcr dist_coast rugged desert2 gemstones2 ///
		ecodivfao, r
		test conflict_brecke+conflict_breckeXwb_ssa=0
		local Fstat=r(F)
		local Pval=r(p)
		outreg2 using tableA7, keep($mainrhs) $outopts ///
		addstat(F,`Fstat',p,`Pval') addtext(Continent FE, Yes, Controls, Yes) append
}

*** Re-estimate spec 6 in Tables 4 and 5 after controlling for oil production
foreach X in inctaximf9014 avg_civilwar00 {
		reg `X' $mainrhs $baselinecont ///
		malfal kgatr distcr dist_coast rugged desert2 gemstones2 ///
		oilsupply, r
		test conflict_brecke+conflict_breckeXwb_ssa=0
		local Fstat=r(F)
		local Pval=r(p)
		outreg2 using tableA7, keep($mainrhs) $outopts ///
		addstat(F,`Fstat',p,`Pval') addtext(Continent FE, Yes, Controls, Yes) append
}
cap erase tableA7.txt

*** Table A8: Robustness: Region Fixed Effects
*Re-estimate spec 1 in Tables 2 and 3 after controlling for 14 macro-geographical regions (excluding continental FEs)
*Load Data
cd "$cleandata"
use "dfo_cross_section_ehdr", clear
cd "$output"

*Restrict sample
keep if americas==0
keep if oceania==0

cap erase tableA8.txt
cap erase tableA8.xml
foreach X in inctaximf9014 avg_civilwar00 {
		xi : reg `X' $mainrhs $maincont wb_ssa i.unregion, r
		test conflict_brecke+conflict_breckeXwb_ssa=0
		local Fstat=r(F)
		local Pval=r(p)
		outreg2 using tableA8, keep($mainrhs) $outopts ///
		addstat(F,`Fstat',p,`Pval') addtext(Continent FE, Yes, Controls, Yes) append
}
cap erase tableA8.txt

*** Table A9: Robustness: Historical Conflict, 1400-1600
*Conflict in other periods
*Load Data
cd "$cleandata"
use "dfo_cross_section_ehdr", clear
cd "$output"

*Restrict sample
keep if americas==0
keep if oceania==0

cap erase tableA9.txt
cap erase tableA9.xml
foreach depvar in inctaximf9014 avg_civilwar00 {
	foreach rhsvar in conflict_brecke_1400_1600 {
	preserve
		replace conflict_brecke=`rhsvar'
		replace conflict_breckeXwb_ssa=`rhsvar'*wb_ssa
		reg `depvar' $mainrhs $baselinecont, r
			test conflict_brecke+conflict_breckeXwb_ssa=0
			local Fstat=r(F)
			local Pval=r(p)
		outreg2 using tableA9, keep($mainrhs) $outopts addstat(F,`Fstat',p,`Pval') ///
			addtext(Robustness, Conflict exposure is `rhsvar') append
	restore
	}
}
cap erase tableA9.txt

*** Table A10: Robustness: Alternative Periodizations of Civil Conflict
* Put PRIO data for 3 sub-periods on LHS
*Load Data
cd "$cleandata"
use "dfo_cross_section_ehdr", clear
cd "$output"

*Restrict sample
keep if americas==0
keep if oceania==0

cap erase tableA10.txt
cap erase tableA10.xml
foreach depvar in  priocw60_14  priocw60_90 priocw90_14 {
	local lvar : variable label `depvar'
	reg `depvar' $mainrhs $baselinecont, r
		test conflict_brecke+conflict_breckeXwb_ssa=0
		local Fstat=r(F)
		local Pval=r(p)
	outreg2 using tableA10, keep($mainrhs) $outopts addstat(F,`Fstat',p,`Pval') ///
		addtext(Robustness, `lvar' as LHS) append
}
cap erase tableA10.txt

*** Table A11: Robustness: Exclude Angola
*Re-estimate spec 1 in Tables 2 and 3 after dropping Angola
*Load Data
cd "$cleandata"
use "dfo_cross_section_ehdr", clear
cd "$output"
drop if country_ag=="Angola"

*Restrict sample
keep if americas==0
keep if oceania==0

cap erase tableA11.txt
cap erase tableA11.xml
foreach X in avg_civilwar00 {
		reg `X' $mainrhs $baselinecont, r
		test conflict_brecke+conflict_breckeXwb_ssa=0
		local Fstat=r(F)
		local Pval=r(p)
		outreg2 using tableA11, keep($mainrhs) $outopts ///
		addstat(F,`Fstat',p,`Pval') addtext(Continent FE, Yes, Controls, Yes) append
}

*So other globals unaffected: recode WB-SSA as if Africa and North Africa as if 0
gen africa=northafrica==1
	replace africa=1 if wb_ssa==1
replace conflict_breckeXwb_ssa=conflict_brecke*africa
	label var conflict_breckeXwb_ssa "Avg Conflict X Africa"
replace wb_ssa=africa
	replace northafrica=0
	label var wb_ssa "Avg Conflict X Africa"
	
foreach X in avg_civilwar00 {
		reg `X' $mainrhs $baselinecont, r
		test conflict_brecke+conflict_breckeXwb_ssa=0
		local Fstat=r(F)
		local Pval=r(p)
		outreg2 using tableA11, keep($mainrhs) $outopts ///
		addstat(F,`Fstat',p,`Pval') addtext(Continent FE, Yes, Controls, Yes) append
}
cap erase tableA11.txt

*************** Other results from footnotes
***************
***************

*** (Footnote 11) Re-estimate spec 1 in Tables 2 and 3 after coding conflict as log(1+conflict)
*Load Data
cd "$cleandata"
use "dfo_cross_section_ehdr", clear
cd "$output"

*Restrict sample
keep if americas==0
keep if oceania==0

replace conflict_brecke=ln(1+conflict_brecke)
replace conflict_breckeXwb_ssa=conflict_brecke*wb_ssa

cap erase footnotes_tables2_3_lnconflict.txt
cap erase footnotes_tables2_3_lnconflict.xml
foreach X in inctaximf9014 avg_civilwar00 {
		reg `X' $mainrhs $baselinecont, r
		test conflict_brecke+conflict_breckeXwb_ssa=0
		local Fstat=r(F)
		local Pval=r(p)
		outreg2 using footnotes_tables2_3_lnconflict, keep($mainrhs) $outopts ///
		addstat(F,`Fstat',p,`Pval') addtext(Continent FE, Yes, Controls, Yes) append
}
cap erase footnotes_tables2_3_lnconflict.txt

*** Re-estimate spec 1 in Tables 2 and 3 after controlling for conflicts fought in neighbor countries
*Load Data
cd "$cleandata"
use "dfo_cross_section_ehdr", clear
cd "$output"

*Restrict sample
keep if americas==0
keep if oceania==0

cap erase footnotes_tables2_3_neighbors.txt
cap erase footnotes_tables2_3_neighbors.xml
foreach X in inctaximf9014 avg_civilwar00 {
		reg `X' $mainrhs $baselinecont ///
			adjaltconflict_brecke adjaltconflict_breckeXwb_ssa , r
		test conflict_brecke+conflict_breckeXwb_ssa=0
		local Fstat=r(F)
		local Pval=r(p)
		outreg2 using footnotes_tables2_3_neighbors, keep($mainrhs) $outopts ///
		addstat(F,`Fstat',p,`Pval') addtext(Continent FE, Yes, Controls, Yes) append
}
cap erase footnotes_tables2_3_neighbors.txt

*** (Footnote 18) Re-estimate spec 1 in Table 3 for same sample as in spec 1 of Table 2
*Load Data
cd "$cleandata"
use "dfo_cross_section_ehdr", clear
cd "$output"

*Restrict sample
keep if americas==0
keep if oceania==0

cap erase footnotes_table3_table2sample.txt
cap erase footnotes_table3_table2sample.xml
reg avg_civilwar00 $mainrhs $baselinecont ///
		if inctaximf9014!=., r
		test conflict_brecke+conflict_breckeXwb_ssa=0
		local Fstat=r(F)
		local Pval=r(p)
		outreg2 using footnotes_table3_table2sample, keep($mainrhs) $outopts ///
		addstat(F,`Fstat',p,`Pval') addtext(Continent FE, Yes, Controls, Yes, Sample, Same obs as inctaximf9014) append

cap erase footnotes_table3_table2sample.txt

*** (Footnote 25) Re-estimate spec 1 in Tables 2 and 3 after controlling for migrant share
*Load Data
cd "$cleandata"
use "dfo_cross_section_ehdr", clear
cd "$output"

*Restrict sample
keep if americas==0
keep if oceania==0

cap erase footnotes_tables2_3_pnative.txt
cap erase footnotes_tables2_3_pnative.xml
foreach X in inctaximf9014 avg_civilwar00 {
		reg `X' $mainrhs $baselinecont ///
			pnative, r
		test conflict_brecke+conflict_breckeXwb_ssa=0
		local Fstat=r(F)
		local Pval=r(p)
		outreg2 using footnotes_tables2_3_pnative, keep($mainrhs) $outopts ///
		addstat(F,`Fstat',p,`Pval') addtext(Continent FE, Yes, Controls, Yes) append
}
cap erase footnotes_tables2_3_pnative.txt

*** (Footnote 28) Re-estimate specs 3-4 in Table 8 using all conflicts fought in Africa b/w 1850-99
cd "$cleandata"
use "dfo_cross_section_ehdr", clear
cd "$output"
keep if americas==0
keep if oceania==0

cap erase footnotes_table8_allconflicts.txt
cap erase footnotes_table8_allconflicts.xml
	*Column 3: No colonizer dummies
foreach X in conflict_brecke {
		reg conflict_brecke_ssa1850 `X' ln_pd1500 ln_yst ln_suitavg ln_abslat area2 if wb_ssa==1, r
		outreg2 `X' using footnotes_table8_allconflicts, keep($mainrhs) $outopts ///
		addtext(Continent FE, Yes, Controls, Yes) append
}
	*Column 4: Colonizer dummies
foreach X in conflict_brecke {
		reg conflict_brecke_ssa1850 `X' ln_pd1500 ln_yst ln_suitavg ln_abslat area2 ///
		colony_esp colony_gbr colony_fra colony_prt colony_oeu ///
		if wb_ssa==1, r
		outreg2 `X' using footnotes_table8_allconflicts, keep($mainrhs) $outopts ///
		addtext(Continent FE, Yes, Controls, Colonial origins) append
}
cap erase footnotes_table8_allconflicts.txt
